package decorador;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;

import modelos.ModeloProducto;

public class DecoradorListarMasUsados extends Decorador{
	private boolean asc;
	private boolean desc;

	@Override
	public void listar(){
		lista = new LinkedList<String []>();
	    String tira="SELECT raciones , descripcion , cod FROM  Ingrediente,(SELECT SUM(racion) AS raciones,cod_ing AS cod FROM IngredientexProducto  GROUP BY cod_ing) Suma WHERE Ingrediente.codigo=Suma.cod ORDER BY raciones ";
	    if(asc)
	        tira+= "ASC";
	    if(desc)
	        tira+= "DESC";
	    modelo.abrirConexion();
	    try {
	        Statement stam = modelo.getConexion().createStatement();
	        ResultSet rs = stam.executeQuery(tira);
	        
	        while (rs.next()){
	            String [] s = {""+rs.getDouble(1), rs.getString(2), ""+rs.getInt(3)};
	            lista.add(s);
	        }
	  } catch (SQLException ex) {
	        Logger.getLogger(ModeloProducto.class.getName()).log(Level.SEVERE, null, ex);
	    }
	}

	public boolean isAsc() {
		return asc;
	}

	public void setAsc(boolean asc) {
		this.asc = asc;
	}

	public boolean isDesc() {
		return desc;
	}

	public void setDesc(boolean desc) {
		this.desc = desc;
	}
	
	
}
